home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-coverdisks-
/
126a
/
football
/
user
/
endofseason.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-22
|
20KB
|
678 lines
/* ***********************************************************************
END OF SEASON PROGRAM FOR FOOTBALL REXX SUITE
-----------------------------------------------
Copyright Mark Naughton 1997
Version Date History
--------------------------------------------------------------------------
1.0 061097 First release - after about 10 days and loads of
hassle and numerous variations in the method for
swapping/deleting teams between divisions.
**************************************************************************
Procedure
---------
1. Check files exist.
2. Read number of divisions and divisions. Then store.
3. Search all leagues/divisions to see if all matches have been played,
if not, then give error and exit.
4. Create all league/division tables and save to temporary files.
5. Display the winner, teams relegated and teams promoted for each
division.
6. Loop. Read teams from division then swap/delete those teams that have
been relegated/promoted between adjoining leagues/divisions. Write to
temporary file when complete. End loop.
7. Loop. Read previous '.df' file and using data from temporary files
created in (6), create '_NewData.df' files for each league/division.
End loop.
8. Display message about '_NewData.df' files.
9. Display final league/division tables.
10.Erase temporary files. Exit.
************************************************************************** */
PARSE ARG league_stuff
version = 1
input_file = '.df'
input2_file = '.sf'
league_file = "Data/" || league_stuff
stored_divs. = '???'
league_title = '*LEAGUE_NAME='
num_divs = '*NUM_DIVISIONS='
divisions = '*DIVISIONS='
releg = '*RELEGATION='
promoted = '*PROMOTED='
not_played = '__ __'
ndivs = 1
divs = ''
promo = 0
relg = 2
separator = '*'
defcts. = '???'
titles. = '???'
names. = '???'
defs. = '???'
div1. = '???'
if exists(league_file || input_file) = 0 then exit
if exists(league_file || input2_file) = 0 then exit
if open(datafile,league_file || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(num_divs,line) > 0 then ndivs = delstr(line,1,15)
if pos(divisions,line) > 0 then divs = delstr(line,1,11)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"league_file || input_file"' file."
exit
end
stored_divs.1 = league_file
do i=2 to ndivs
stored_divs.i = "Data/"||word(divs,i-1)
end
access = "NONE"
do i=1 to ndivs
if open(datafile,stored_divs.i || input2_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(not_played,line) > 0 then do
access = stored_divs.i
leave
end
end
close(datafile)
end
if pos("NONE",access) = 0 then do
say "League '"access"' has not finished. Enter the scores then"
say "run this program again to close the season."
exit
end
access = "NONE"
end
/* All matches have been played in the league, so the program continues... */
/* create league tables */
do i=1 to ndivs
call create_table(stored_divs.i)
end
/* print title and winners/losers */
say
say " End Of Season"
say " ---------------"
say
say
defcnt = 0
do i=1 to ndivs
if open(datafile,stored_divs.i || input_file,'r') then do
do while ~eof(datafile)
line = readln(datafile)
if pos(league_title,line) > 0 then title = delstr(line,1,13)
if pos(releg,line) > 0 then relg = delstr(line,1,12)
if pos(promoted,line) > 0 then promo = delstr(line,1,10)
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open '"stored_divs.i || input_file"' file."
exit
end
parse var stored_divs.i . "/" name .
a = 0
if open(datafile,"RAM:"||name||".final_table",'r') then do
do while ~eof(datafile)
line = readln(datafile)
a = a + 1
div1.a = line
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open 'RAM:"name".final_table' file."
exit
end
say " League : "title
titles.i = title
say
defcnt = defcnt + 1
if i=1 then do
say " Winner : "substr(div1.1,1,35)
defs.defcnt = name" WINR "trim(substr(div1.1,1,35))
end
else do
do b=1 to promo
if b=1 then do
say " Promoted : "substr(div1.b,1,35)
defs.defcnt = name" PROM * "trim(substr(div1.b,1,35))
end
else do
say " "substr(div1.b,1,35)
defs.defcnt = defs.defcnt" * "trim(substr(div1.b,1,35))
end
end
end
defcnt = defcnt + 1
say
start= a - relg /* was start+1 */
do b = start to a
if b = start then do
say " Relegated : "substr(div1.b,1,35)
defs.defcnt = name" RELG * "trim(substr(div1.b,1,35))
end
else do
say " "substr(div1.b,1,35)
defs.defcnt = defs.defcnt" * "trim(substr(div1.b,1,35))
end
end
say
say
end
say " ---------------------"
/* swap/delete teams between divisions, write new files */
do i=1 to ndivs
parse var stored_divs.i . "/" name . /* read teams into memory */
n = 0
if open(datafile,"RAM:"||name||".final_table",'r') then do
do while ~eof(datafile)
line = readln(datafile)
n = n + 1
div1.n = trim(substr(line,1,35))
end
close(datafile)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Unable to open 'RAM:"name".final_table' file."
exit
end
b = 0
do a=1 to defcnt
if pos(name,defs.a) = 0 then
iterate
if pos("RELG",defs.a) > 0 then do /* Check for relegation code */
b = a + 1
if pos("PROM",defs.b) = 0 then do
do m=1 to n
if pos(div1.m,defs.a) > 0 then /* delete relegated teams */
div1.m = "Deleted Team"
end
end
else do
do m=1 to n
if pos(div1.m,defs.a) > 0 then /* delete relegated teams... */
div1.m = "Deleted Team"
end
parse var defs.b . "* " names.1 " * " names.2 " * " names.3 " * " names.4 " * " names.5 " * " names.6 " *"
c = 1
if div1.n = '' then
n = n - 1
do while names.c ~='' /* ...then add the newly promoted ones! */
n = n + 1
div1.n = names.c
c = c + 1
end
end
if open(datafile2,"RAM:"word(defs.a,1)".teams",'w') then do
do p=1 to n
if pos("Deleted Team",div1.p) = 0 then /* create teams file in RAM: */
writeln(datafile2,div1.p)
end
close(datafile2)
end
else do
say
say "ERROR : (EndOfSeason)"
say
say "Cannot write to 'RAM:"word(defs.a,1)".teams'."
exit
end
end
else do
if pos("PROM",defs.a) > 0 then do /* Check for promotion code */
b = a - 1
if b=0 then
iterate
if pos("RELG",defs.b) = 0 then do
do m=1 to n
if pos(div1.m,defs.a) > 0 then /* delete promoted teams */
div1.m = "Deleted Team"
end
end
else do
do m=1 to n /* delete promoted teams... */
if pos(div1.m,defs.a) > 0 then
div1.m = "Deleted Team"
end
parse var defs.b